#!/bin/bash
#creates a fading GIF slide show of all images in a dir
#created by Kris Occhipinti
#Wed Feb 15th 2012
#http://filmsbykris.com
#GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
random=$RANDOM
rm -fr /tmp/123
mkdir /tmp/123
mkdir /tmp/$random
clear
x=0
let y=100

for img in $(ls *.jpg *.png *.bmp )
do
 if [ "$x" = "0" ]
 then 
   x="$img"
   z="$img"
 else
  echo -n "Creating Fade Images..."
  for i in {000..100..5}
  do 
    composite -dissolve $i "$img" "$x" -alpha Set /tmp/123/$i.png
    echo -n "."
  done
  x="$img"

  echo ""
  
  #Hold Still image for 10 frames
  for p in {101..111}
  do
      cp /tmp/123/100.png /tmp/123/$p.png
  done

  echo "Combining Images into GIF File /tmp/$random/fade_$y.gif..."
  convert -delay 20 -loop 0 /tmp/123/*.png /tmp/$random/fade_$y.gif
  let y+=1
  rm -fr /tmp/123/*
 fi
done

echo -n "Creating Final Loop Back..."
for i in {000..100..5}
do 
    composite -dissolve $i "$z" "$img" -alpha Set /tmp/123/$i.png
    echo -n "."
done

#Hold Still image for 10 frames
for p in {101..111}
do
    cp /tmp/123/100.png /tmp/123/$p.png
done

convert -delay 20 -loop 0 /tmp/123/*.png /tmp/$random/fade_$y.gif
echo ""
convert /tmp/$random/*.gif fade_$random.gif
echo "File fade_$random.gif Created."

echo "Cleaning up TMP DIR..."
rm -fr /tmp/$random/

xdg-open "fade_$random.gif"